<?php
// +----------------------------------------------------------------------
// | WoShiMaiJia Projcet 
// +----------------------------------------------------------------------
// | Copyright (c) 2010-2011 http://woshimaijia.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: xinqiyang <xinqiyang@gmail.com>
// +----------------------------------------------------------------------

/**
 * Upload Action
 * @author xinqiyang
 *
 */
class UploadAction extends AppBaseAction
{
	public function index()
	{
		logTrace(__CLASS__.'/'.__FUNCTION__.':UPLOAD FILE NOW '.$_GET['type']);
		//set upload type
		$objects = array('product','brand','account','post','group');
		$data = '';
		$info = 'Upload Error';
		$status = 1;
		if(in_array($_GET['type'], $objects)){
			$r = ImageService::saveImage();
			$id = $r;
			
			if($r)
			{
				//do save user info then jump
				$array['id'] = userID();
				$array['image_id'] = $id;
				
				
				
				$datas['id']= $id;
				$datas['filename']= $id;
				$datas['desc']= '';
				$datas['createtime']= time();
				$datas['status']='0';
				$datas['remoteurl']='';
				$datas['url']='';
				//@todo need to change
				
				$datas['model']= $_GET['type'];
				$datas['user_id']=userID();
				$rsaveImage = ImageLogic::addImage($datas);
				$rsaveAvatar = AccountLogic::actSave($array);
				if($rsaveAvatar && $rsaveImage) {
					AccountService::setSession($array['id']);
				}
				//jump url
				$data = '/account/setting';
				$info = '';
				$status = 0;
			}
		}
		$this->ajaxReturn($data,$info,$status);
	}
}